package org.shop.util;

import java.util.List;

/**
 * 分页工具类 当前页 每页显示记录数 总记录数 总页数 数据
 * 
 * @author Administrator
 *
 */
public class PagerUtil<T> {
	/**
	 * 当前页
	 */
	private int currentPage;

	/**
	 * 每页显示记录数
	 */
	private int pageCount;

	/**
	 * 总记录数
	 */
	private int totalRecordCount;

	/**
	 * 总页数
	 */
	private int totalPageCount;

	/**
	 * 页面显示的数据
	 */
	List<T> data;

	
	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		
		if(currentPage<=0) {
			this.currentPage = 1 ;
		} else if(currentPage > this.getTotalPageCount()) {
			this.currentPage = this.getTotalPageCount() ;
		} else {
			this.currentPage = currentPage;
		}
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getTotalRecordCount() {
		return totalRecordCount;
	}

	public void setTotalRecordCount(int totalRecordCount) {
		this.totalRecordCount = totalRecordCount;
	}

	/**
	 * 返回总页数 （注意：必须先初始化总记数和每页显示记录数）
	 * 10 5 = 2
	 * 12 5 = 2 + 1 
	 * 9  5 = 1 + 1 = 2
	 * 
	 * @return
	 */
	public int getTotalPageCount() {
		// 判断总记录数 和 每页记录数是否能整除
		if(this.getTotalRecordCount() % this.getPageCount()==0) {
			return this.getTotalRecordCount() / this.getPageCount() ;
		}
		return this.getTotalRecordCount() / this.getPageCount() + 1;
	}

//	public void setTotalPageCount(int totalPageCount) {
//		this.totalPageCount = totalPageCount;
//	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}
}
